package com.emep.changzhi.analyse.http.aqi;

import com.emep.changzhi.analyse.entity.aqi.DataAqiInfo;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.aqi.DataAqiInfoService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author yangj
 * @version V1.0
 * @Description: DOTO
 * @date 2018/3/28  14:40
 */
@RestController
@RequestMapping("ranking")
public class DataAqiInfoController {

    @Autowired
    private DataAqiInfoService dataAqiInfoService;


    /**
     * 获取天气情况
     * */
    @GetMapping(value = "site")
    public ResultBean<Collection<DataAqiInfo>> findweather(@RequestParam Map<String, Object> payload){
        List<DataAqiInfo> dataAqiInfoList = new ArrayList<DataAqiInfo>();
        ResultBean result = DataValidator.validateMapData(payload, "cityCode");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            if(DataValidator.validateMapData(payload, "pollutionCode").getCode() == Constant.RESULT_CODE_SUCCESS){
                dataAqiInfoList = dataAqiInfoService.findRankBysite(payload.get("cityCode").toString() , payload.get("pollutionCode").toString());
            }else{      //默认为PM2.5排名
                dataAqiInfoList = dataAqiInfoService.findRankBysite(payload.get("cityCode").toString() , "pm25");
            }
            return new ResultBean<Collection<DataAqiInfo>>(dataAqiInfoList);
        }
        return  result;
    }


}
